package com.example.xpvideo.Controller;

import com.example.xpvideo.entity.LsIntegralSystem;
import com.example.xpvideo.entity.ResponseResult;
import com.example.xpvideo.entity.req.SignInRecordsReq;
import com.example.xpvideo.enums.ErrCodeEnum;
import com.example.xpvideo.service.LsIntegralSystemService;
import com.example.xpvideo.service.LsSignInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author hjt
 * @create 2021-08-31 17:27
 * @describe：签到系统
 */
@RestController
@RequestMapping("signIn")
public class IntegralSystemController {
    @Autowired
    private LsIntegralSystemService integralSystemService;
    @Autowired
    private LsSignInService signInService;

    /**
     * 查询签到送积分规则
     * @return
     */
    @GetMapping("integralRule")
    public ResponseResult integralRule() {
        LsIntegralSystem integralSystem = integralSystemService.getOne(null);
        return ResponseResult.responseResult(0, integralSystem);
    }

    /**
     * 修改签到送积分规则
     *
     * @return
     */
    @PostMapping("updateRule")
    public ResponseResult updateRule(@RequestBody LsIntegralSystem integralSystem) {
        if (null != integralSystem.getId()) {
            boolean b = integralSystemService.updateById(integralSystem);
            return b ? ResponseResult.responseResult(0) : ResponseResult.responseResult(ErrCodeEnum.unknown_20002, null);
        }
        return ResponseResult.responseResult(ErrCodeEnum.unknown_10001, null);
    }

    /**
     * 用户签到
     * @return
     */
    @PostMapping("signInOperation")
    public ResponseResult signInOperation(@RequestBody Map<String, String> params) {
        return signInService.signInOperation(params);
    }

    /**
     * 查询签到记录
     */
    @GetMapping("signInRecords")
    public ResponseResult signInRecords(@RequestBody SignInRecordsReq signInRecordsReq) {
        return signInService.signInRecords(signInRecordsReq);
    }
}
